package cn.djx.springsecurity.controller;

import cn.djx.springsecurity.entity.Users;
import cn.djx.springsecurity.service.LoginService;
import cn.djx.springsecurity.utils.ResponseResult;
import com.fasterxml.jackson.core.JsonProcessingException;
import jakarta.annotation.Resource;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/users")
public class LoginController {
    @Resource
    private LoginService loginService;

    @PostMapping("/login")
    public ResponseResult login(@RequestBody Users users) throws JsonProcessingException {
        return loginService.login(users);
    }
    @PostMapping("/register")
    public ResponseResult register(@RequestBody Users users) {
        return loginService.register(users);
    }

    @PostMapping("/logout")
    public ResponseResult logout() {
        return loginService.logout();
    }

    @GetMapping("/hello")
    //@PreAuthorize("hasAuthority('system:test:list')")
    //@PreAuthorize("hasAnyAuthority('system:test:list','system:test:add')")
    @PreAuthorize("@ex.hasPermission('system:test:list')")
    public String hello() {
        return "hello";
    }

    @GetMapping("/test")
    public String test() {
        return "test";
    }
}
